babl: get rid of RGB_LUMINANCE constants
authorØyvind Kolås <pippin@gimp.org>
Sat, 19 Aug 2017 01:18:29 +0000 (03:18 +0200)
committerØyvind Kolås <pippin@gimp.org>
Sat, 19 Aug 2017 01:18:34 +0000 (03:18 +0200)
babl/babl-format.c
babl/babl-space.c
babl/babl.h
babl/base/model-gray.c
babl/base/rgb-constants.h [deleted file]
extensions/grey.c

index a2c8e1734b1e45ad188fb1aea1056cc12daac435..6a7ebb2ab35ed7a60970e93be07ca5ba8045ce9c 100644 (file)
@@ -104,7 +104,7 @@ format_new (const char      *name,
   if (space == babl_space ("sRGB"))
     babl->format.model      = model;
   else
-    babl->format.model      = babl_remodel_with_space (model, space);
+    babl->format.model      = (void*)babl_remodel_with_space ((void*)model, space);
 
   memcpy (babl->format.component, component, sizeof (BablComponent *) * components);
   memcpy (babl->format.type, type, sizeof (BablType *) * components);
index 2d51d548aefe1a54875f53bbff42ec70a41adcbe..e6ef5ed860ec2f57c8dd0fd6b91f0dd8d13fb9d1 100644 (file)
@@ -329,3 +329,8 @@ void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb)
 {
   _babl_space_from_xyz (space, xyz, rgb);
 }
+
+double * babl_space_get_rgbtoxyz (const Babl *space)
+{
+  return space->space.RGBtoXYZ;
+}
index c227703e044e73d8e9e921ab92f4ed6e14c685d1..e24640effd59db8f035d9833c118387d8d7ca223 100644 (file)
@@ -122,6 +122,10 @@ const Babl * babl_space_rgb_chromaticities (const char *name,
                                             const Babl *trc_green,
                                             const Babl *trc_blue);
 
+double * babl_space_get_rgbtoxyz (const Babl *space);
+void babl_space_to_xyz   (const Babl *space, const double *rgb, double *xyz);
+void babl_space_from_xyz (const Babl *space, const double *xyz, double *rgb);
+
 /**
  * babl_format:
  *
index 16b1811c5b6c7924f052b76fc723bf1a4171fc78..36eff162062f417afea74cd25129244052d9d3e2 100644 (file)
@@ -22,7 +22,6 @@
 #include "babl-classes.h"
 #include "babl.h"
 #include "babl-ids.h"
-#include "rgb-constants.h"
 #include "math.h"
 #include "babl-base.h"
 
@@ -114,6 +113,11 @@ rgba_to_graya (Babl *conversion,
                char *dst,
                long  n)
 {
+  const Babl *space = babl_conversion_get_source_space (conversion);
+  double RGB_LUMINANCE_RED   = space->space.RGBtoXYZ[3];
+  double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4];
+  double RGB_LUMINANCE_BLUE  = space->space.RGBtoXYZ[5];
+
   while (n--)
     {
       double red, green, blue;
@@ -143,6 +147,11 @@ rgba_to_gray (Babl *conversion,
               char *dst,
               long  n)
 {
+  const Babl *space = babl_conversion_get_source_space (conversion);
+  double RGB_LUMINANCE_RED   = space->space.RGBtoXYZ[3];
+  double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4];
+  double RGB_LUMINANCE_BLUE  = space->space.RGBtoXYZ[5];
+
   while (n--)
     {
       double red, green, blue;
@@ -176,6 +185,10 @@ rgb_to_gray_2_2 (Babl  *conversion,
 {
   const Babl *space = babl_conversion_get_destination_space (conversion);
   const Babl *trc = space->space.trc[0];
+  double RGB_LUMINANCE_RED   = space->space.RGBtoXYZ[3];
+  double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4];
+  double RGB_LUMINANCE_BLUE  = space->space.RGBtoXYZ[5];
+
   BABL_PLANAR_SANITY
   while (n--)
     {
@@ -352,6 +365,11 @@ rgba_to_gray_alpha_premultiplied (Babl   *conversion,
                                   int   *dst_pitch,
                                   long   n)
 {
+  const Babl *space = babl_conversion_get_source_space (conversion);
+  double RGB_LUMINANCE_RED   = space->space.RGBtoXYZ[3];
+  double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4];
+  double RGB_LUMINANCE_BLUE  = space->space.RGBtoXYZ[5];
+
   BABL_PLANAR_SANITY;
   assert (src_bands == 4);
   assert (dst_bands == 2);
@@ -450,6 +468,9 @@ rgba2gray_gamma_2_2_premultiplied (Babl *conversion,
 {
   const Babl *space = babl_conversion_get_destination_space (conversion);
   const Babl *trc = space->space.trc[0];
+  double RGB_LUMINANCE_RED   = space->space.RGBtoXYZ[3];
+  double RGB_LUMINANCE_GREEN = space->space.RGBtoXYZ[4];
+  double RGB_LUMINANCE_BLUE  = space->space.RGBtoXYZ[5];
 
   while (n--)
     {
diff --git a/babl/base/rgb-constants.h b/babl/base/rgb-constants.h
deleted file mode 100644 (file)
index 03810d6..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/* babl - dynamically extendable universal pixel conversion library.
- * Copyright (C) 2005, Øyvind Kolås.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-/*
- * These sRGB Y values have been adapted to the ICC spec D50 illuminant.
- * They match the Y values in the GEGL and GIMP built-in sRGB profiles,
- * which match the Y values in the ArgyllCMS sRGB.icm profile.
- *
- * For more information, see this thread and these bug reports:
- * https://mail.gnome.org/archives/gimp-developer-list/2013-September/msg00113.html
- * https://bugzilla.gnome.org/show_bug.cgi?id=723787
- * https://bugzilla.gnome.org/show_bug.cgi?id=724822
- */
-
-#define RGB_LUMINANCE_RED    (0.22248840)
-#define RGB_LUMINANCE_GREEN  (0.71690369)
-#define RGB_LUMINANCE_BLUE   (0.06060791)
index b39406424088469a13c5b3e38df30fb8857704ce..f997dd8d18892de7793a0588d636d2a89349b893 100644 (file)
@@ -22,7 +22,6 @@
 #include "babl.h"
 
 #include "base/util.h"
-#include "base/rgb-constants.h"
 #include "extensions/util.h"
 
 /* There was some debate on #gimp about whether these constants
  */
 
 /* Float versions of the double constants in rgb-constants.h */
-static const float RGB_LUMINANCE_RED_FLOAT = RGB_LUMINANCE_RED;
-static const float RGB_LUMINANCE_GREEN_FLOAT = RGB_LUMINANCE_GREEN;
-static const float RGB_LUMINANCE_BLUE_FLOAT = RGB_LUMINANCE_BLUE;
 
 static long
 conv_rgbaF_linear_y8_linear (const Babl *conversion,unsigned char *src,
                              unsigned char *dst,
                              long           samples)
 {
-  static const float RGB_LUMINANCE_RED_FLOAT = RGB_LUMINANCE_RED;
-  static const float RGB_LUMINANCE_GREEN_FLOAT = RGB_LUMINANCE_GREEN;
-  static const float RGB_LUMINANCE_BLUE_FLOAT = RGB_LUMINANCE_BLUE;
+  const Babl *space = babl_conversion_get_source_space (conversion);
+  double *rgbtoxyz = babl_space_get_rgbtoxyz (space);
+  const float RGB_LUMINANCE_RED_FLOAT = rgbtoxyz[3];
+  const float RGB_LUMINANCE_GREEN_FLOAT = rgbtoxyz[4];
+  const float RGB_LUMINANCE_BLUE_FLOAT = rgbtoxyz[5];
 
   float *s = (float *) src;
   long   n = samples;
@@ -69,6 +67,11 @@ conv_rgbaF_linear_yF_linear (const Babl *conversion,unsigned char *src,
                              unsigned char *dst,
                              long           samples)
 {
+  const Babl *space = babl_conversion_get_source_space (conversion);
+  double *rgbtoxyz = babl_space_get_rgbtoxyz (space);
+  const float RGB_LUMINANCE_RED_FLOAT = rgbtoxyz[3];
+  const float RGB_LUMINANCE_GREEN_FLOAT = rgbtoxyz[4];
+  const float RGB_LUMINANCE_BLUE_FLOAT = rgbtoxyz[5];
 
   float *s = (float *) src;
   float *d = (float *) dst;
@@ -92,6 +95,11 @@ conv_rgbaF_linear_yaF_linear (const Babl *conversion,unsigned char *src,
                               unsigned char *dst,
                               long           samples)
 {
+  const Babl *space = babl_conversion_get_source_space (conversion);
+  double *rgbtoxyz = babl_space_get_rgbtoxyz (space);
+  const float RGB_LUMINANCE_RED_FLOAT = rgbtoxyz[3];
+  const float RGB_LUMINANCE_GREEN_FLOAT = rgbtoxyz[4];
+  const float RGB_LUMINANCE_BLUE_FLOAT = rgbtoxyz[5];
 
   float *s = (float *) src;
   float *d = (float *) dst;